﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.InsertLocationInsideSeam.CApIlisSeamLocationValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.InsertLocationInsideSeam;

internal class CApIlisSeamLocationValidator : ITxValidator
{
  private Type m_validType = typeof (TxRoboticSeamLocationOperation);

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    errorMessage = "";
    return this.DoesPassFilter(obj, out errorMessage);
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    errorMessage = (string) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (text != null)
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(text);
    bool flag;
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
    {
      flag = false;
      foreach (ITxObject itxObject in (Collection<ITxObject>) txObjectList)
      {
        if (this.IsValidObject(itxObject, out errorMessage))
        {
          flag = true;
          break;
        }
      }
    }
    else
    {
      errorMessage = StringTable.INVALID_SEAM_LOCATION;
      flag = false;
    }
    return flag;
  }

  public ITxObject GetObject(string text)
  {
    ITxObject itxObject1 = (ITxObject) null;
    TxObjectList txObjectList = (TxObjectList) null;
    if (text != null)
      txObjectList = TxApplication.ActiveDocument.GetObjectsByName(text);
    if (txObjectList != null && ((Collection<ITxObject>) txObjectList).Count > 0)
    {
      itxObject1 = ((Collection<ITxObject>) txObjectList)[0];
      foreach (ITxObject itxObject2 in (Collection<ITxObject>) txObjectList)
      {
        if (this.IsValidObject(itxObject2, out string _))
        {
          itxObject1 = itxObject2;
          break;
        }
      }
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = "";
    if (obj != null)
      text = obj.Name;
    return text;
  }

  private bool DoesPassFilter(ITxObject pickedObject, out string errorMessage)
  {
    if (this.m_validType.IsAssignableFrom(pickedObject.GetType()))
    {
      errorMessage = "";
      return true;
    }
    errorMessage = StringTable.INVALID_SEAM_LOCATION;
    return false;
  }
}
